package com.bot.nft.module.cm.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bot.common.pojo.CommonResult;
import com.bot.nft.module.cm.domain.bo.CmNoticeInfoBo;
import com.bot.nft.module.cm.domain.vo.CmNoticeInfoVo;
import com.bot.nft.module.cm.domain.vo.NoticeQueryBo;
import com.bot.nft.module.cm.service.ICmNoticeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 描述: 站内公告
 * 时间: 2023-12-04 10:47
 * 负责人: 卢梦丽
 **/

@RestController
@RequestMapping("/cm")
public class NoticeController {


    @Resource
    public ICmNoticeService iCmNoticeService;

    /**
     * 添加站内公告
     *
     * @param cmNoticeInfoBo
     * @return
     */
    @PostMapping("/addNotice.do")
    public CommonResult<Boolean> addNoticeCmInfo(@RequestBody CmNoticeInfoBo cmNoticeInfoBo) {

        Boolean addNoticeCmInfo = iCmNoticeService.addNoticeCmInfo(cmNoticeInfoBo);
        if (!addNoticeCmInfo) {
            return CommonResult.error();
        }
        return CommonResult.ok();
    }

    /**
     * 修改站内公告
     *
     * @param cmNoticeInfoBo
     * @return
     */
    @PostMapping("/editNotice.do")
    public CommonResult<Boolean> updateNoticeCmInfo(@RequestBody  CmNoticeInfoBo cmNoticeInfoBo) {

        Boolean updateNoticeCmInfo = iCmNoticeService.updateNoticeCmInfo(cmNoticeInfoBo);
        if (!updateNoticeCmInfo) {
            return CommonResult.error();
        }

        return CommonResult.ok();
    }

    /**
     * 查看站内公告
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}/getNotice.do")
    public CommonResult<CmNoticeInfoVo> getNoticeCmInfo(@PathVariable("id") String id) {

        CmNoticeInfoVo noticeCmInfo = iCmNoticeService.getNoticeCmInfo(id);
        return CommonResult.data(noticeCmInfo);

    }

    /**
     * 删除站内公告
     *
     * @param id
     * @return
     */
    @GetMapping ("/{id}/delNotice.do")
    public CommonResult<Boolean> delNoticeCmInfo(@PathVariable("id") String id) {

        Boolean delNoticeCmInfo = iCmNoticeService.delNoticeCmInfo(id);
        if (!delNoticeCmInfo) {
            return CommonResult.error();
        }

        return CommonResult.ok();
    }

    /**
     * 发布站内公告
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}/issueNotice.do")
    public CommonResult<Boolean> issueNoticeCmInfo(@PathVariable("id") String id) {
        Boolean issueNoticeCmInfo = iCmNoticeService.issueNoticeCmInfo(id);

        if (!issueNoticeCmInfo) {
            return CommonResult.error();
        }

        return CommonResult.ok();

    }

    /**
     * 禁用站内公告
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}/disNotice.do")
    public CommonResult<Boolean> disNoticeCmInfo(@PathVariable("id") String id) {

        Boolean disNoticeCmInfo = iCmNoticeService.disNoticeCmInfo(id);
        if (!disNoticeCmInfo) {
            return CommonResult.error();
        }
        return CommonResult.ok();
    }

    /**
     * 分页查询站内公告
     * @param noticeQueryBo 查询类
     * @param pageNo 当前页数
     * @param pageSize 每页条数
     * @return
     */
    @PostMapping("/{pageNo}/{pageSize}/listNotice.do")
    public CommonResult<Page<CmNoticeInfoVo>> queryNoticeByPage(@RequestBody NoticeQueryBo noticeQueryBo, @PathVariable("pageNo") Integer pageNo, @PathVariable("pageSize") Integer pageSize) {
        String keyword = noticeQueryBo.getKeyword();
        Integer status = noticeQueryBo.getStatus();
        Page<CmNoticeInfoVo> cmNoticeInfoVoPageInfo = iCmNoticeService.queryNoticeByPage(keyword,status,pageNo,pageSize);

        return CommonResult.data(cmNoticeInfoVoPageInfo);
    }
}
